package mmoon.mmoonstory.world;

import mmoon.mmoonstory.interfaces.InitWorldGenerator;
import net.minecraft.block.state.IBlockState;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;

import java.util.Random;

public class OreGenerator implements InitWorldGenerator {
    public final WorldGenMinable generator;
    public final int times;
    public final int weight;

    public OreGenerator(IBlockState ore, int size, int times, int weight) {
        this.generator = new WorldGenMinable(ore, size);
        this.times = times;
        this.weight = weight;
        this.Init();
    }

    @Override
    public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
        if (world.provider.getDimension() == 0) {
            generateOre(random, chunkX, chunkZ, world);
        }
    }

    @Override
    public int getWeight() {
        return this.weight;
    }

    public void generateOre(Random random, int chunkX, int chunkZ, World world) {
        for (int i = 0; i < this.times; i++) {
            this.generator.generate(world, random, InitWorldGenerator.randomPosInChunk(random, chunkX, chunkZ, 0, 32));
        }
    }
}
